package com.sa.iam.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.sa.iam.dto.LoginDTO;
import com.sa.iam.service.AuthService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author Architecture Station
 * @version 1.0
 * @website 
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/auth/")
public class AuthController {

    private final AuthService authService;

    @PostMapping("login")
    public SaResult login(@RequestBody LoginDTO loginDTO) {
       return authService.login(loginDTO);
    }

    // 查询登录状态
    @GetMapping("isLogin")
    public SaResult isLogin() {
        return SaResult.ok("是否登录：" + StpUtil.isLogin());
    }


    // 测试注销
    @DeleteMapping("logout")
    public SaResult logout() {
        StpUtil.logout();
        return SaResult.ok();
    }


    //测试令牌传递
    @GetMapping("sortToken")
    public SaResult sortToken() {
        return authService.sortToken();
    }

}
